"use strict";
cc._RF.push(module, '4dcd9cs7q9MNY+LUd0TPUX+', 'LongPress');
// eazax-ccc/components/LongPress.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TriggerWay = exports.LONG_PRESS = void 0;
/**
 * 节点长按事件（由 LongPress 组件触发）
 */
exports.LONG_PRESS = 'longpress';
/**
 * 长按触发方式
 */
var TriggerWay;
(function (TriggerWay) {
    /**
     * 到达设定时间后立即触发
     */
    TriggerWay[TriggerWay["Immediately"] = 1] = "Immediately";
    /**
     * 触摸结束后触发
     */
    TriggerWay[TriggerWay["AfterLoosing"] = 2] = "AfterLoosing";
})(TriggerWay = exports.TriggerWay || (exports.TriggerWay = {}));
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var LongPress = /** @class */ (function (_super) {
    __extends(LongPress, _super);
    function LongPress() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.trggerTime = 2;
        _this.trggerWay = TriggerWay.Immediately;
        _this.longPressEvents = [];
        /**
         * 长按是否达成
         */
        _this.hasAccomplished = false;
        return _this;
    }
    LongPress.prototype.onEnable = function () {
        this.registerNodeEvent();
    };
    LongPress.prototype.onDisable = function () {
        this.unregisterNodeEvent();
    };
    LongPress.prototype.registerNodeEvent = function () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
    };
    LongPress.prototype.unregisterNodeEvent = function () {
        this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.off(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
    };
    LongPress.prototype.onTouchStart = function () {
        this.hasAccomplished = false;
        this.scheduleOnce(this.onPressAccomplished.bind(this), this.trggerTime);
    };
    LongPress.prototype.onTouchEnd = function () {
        if (this.hasAccomplished) {
            this.hasAccomplished = false;
            this.trigger();
        }
        this.unscheduleAllCallbacks();
    };
    LongPress.prototype.onTouchCancel = function () {
        if (this.hasAccomplished) {
            this.hasAccomplished = false;
            this.trigger();
        }
        this.unscheduleAllCallbacks();
    };
    /**
     * 长按达成回调
     */
    LongPress.prototype.onPressAccomplished = function () {
        if (this.trggerWay === TriggerWay.Immediately)
            this.trigger();
        else if (this.trggerWay === TriggerWay.AfterLoosing)
            this.hasAccomplished = true;
    };
    /**
     * 触发已注册长按事件
     */
    LongPress.prototype.trigger = function () {
        cc.Component.EventHandler.emitEvents(this.longPressEvents, this);
        this.node.emit(exports.LONG_PRESS, this);
    };
    __decorate([
        property({ tooltip: CC_DEV && '长按触发时间（单位：秒）' })
    ], LongPress.prototype, "trggerTime", void 0);
    __decorate([
        property({ type: cc.Enum(TriggerWay), tooltip: CC_DEV && '长按触发方式' })
    ], LongPress.prototype, "trggerWay", void 0);
    __decorate([
        property({ type: cc.Component.EventHandler, tooltip: CC_DEV && '长按事件列表' })
    ], LongPress.prototype, "longPressEvents", void 0);
    LongPress = __decorate([
        ccclass
    ], LongPress);
    return LongPress;
}(cc.Component));
exports.default = LongPress;

cc._RF.pop();